package com.itheima.controller.backend;

import com.itheima.DTO.SetmealDTO;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/setmeal")
@Slf4j
@Api(tags = "体检套餐管理")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @PostMapping("/findPage")
    @ApiOperation("分页查询体检套餐")
    public PageResult pageQuery(@RequestBody SetmealDTO setmealDTO) {
        log.info("分页查询体检套餐:{}",setmealDTO.toString());
        PageResult pageResult = setmealService.pageQuery(setmealDTO);
        return pageResult;
    }

    @GetMapping("/findById")
    @ApiOperation("根据id查询体检套餐")
    public Result findById(Integer id) {
        log.info("根据id查询体检套餐:{}",id);
        Setmeal setmeal = setmealService.findById(id);
        return new Result(true,"查询体检套餐成功",setmeal);
    }

    //编辑体检套餐
    @PostMapping("/edit")
    @ApiOperation("编辑体检套餐")
    public Result edit(@RequestBody Setmeal setmeal, String checkgroupIds) {
        log.info("编辑体检套餐:{}",setmeal.toString());
        log.info("编辑体检套餐:{}",checkgroupIds);
        setmealService.edit(setmeal,checkgroupIds);
        return new Result(true,"编辑体检套餐成功");
    }

    @PostMapping("/add")
    @ApiOperation("新增体检套餐")
    public Result add(@RequestBody Setmeal setmeal, String checkgroupIds) {
        log.info("新增体检套餐:{}",setmeal.toString());
        log.info("新增体检套餐:{}",checkgroupIds);
        setmealService.add(setmeal,checkgroupIds);
        return new Result(true,"新增体检套餐成功");
    }


}
